const Service = require('egg').Service;
var uuid = require('uuid');

class PageService extends Service {

	async list () {
		const results = await this.app.mysql.get('sys').select('dlq_page', {
			where : { del_flag : '0' },
			orders : [['create_time', 'desc']]
		});
		return results;
	}

	async info (id) {
		const result = await this.app.mysql.get('sys').get('dlq_page', { name : id, });
		return result;
	}

	async update (para) {
		let result = null;

		const conn = this.app.mysql.get('sys');

		const { id } = para;

		if(id != undefined){
			result = await conn.update('dlq_page', {
				...para,
				update_time : conn.literals.now,
			});
		}else{
			result = await conn.insert('dlq_page', {
				id : uuid.v1(),
				...para,
				create_time : conn.literals.now,
				update_time : conn.literals.now,
			});
		}

		return result.affectedRows === 1;
	}



}

module.exports = PageService;

